package com.workday.gridsimulator

/**
	 * Base class for ec2instances
	 * see: http://aws.amazon.com/ec2/instance-types/
	 * 
	 * @param instanceType small,medium,large, extra-large
	 *            
	 * @param computeUnits the number of compute units associated with the instance type
	 *            
	 * @param ratePerHour the cost per hour for the instance type
	 */
class Ec2Instance(val instanceType: String, val computeUnits: Int, val ratePerHour: Double) {

  private def factor = 1.5

  /**
   *  the more EC2 compute units available, the faster execution should be
   *  multiply the EC2 compute units associated with an instanceSize by a made up factor
   *  turn the result into a fraction so when we can multiply it with job execution time it will simulate faster execution
   *  as the compute units go up, the fraction will get smaller and smaller and thus multiplying it by a job exec time will lower the jobs exec time
   * 
   * @param execTime the execution time before considering what ec2Instance it will run on
   */
  def executionTimeModifier(execTime: Double) = {
    val execTimeModifier = (1 / (computeUnits * factor))
    
    //execTime * execTimeModifier
    execTime
  }

  
}

//class LinuxEc2Instance(instanceType:String, computeUnits: Int, ratePerHour: Double) extends Ec2Instance(instanceType, computeUnits, ratePerHour) {}


/**
 * Factory for instantiating Ec2Instance class
 * see: http://aws.amazon.com/ec2/instance-types/
 */
object Ec2Instance {

  def apply(ec2InstanceType: String): Ec2Instance = {
    if (ec2InstanceType == "small")
      new Ec2Instance(ec2InstanceType, 1, 0.065)
    else if (ec2InstanceType == "medium")
      new Ec2Instance(ec2InstanceType, 2, 0.130)
    else if (ec2InstanceType == "large")
      new Ec2Instance(ec2InstanceType, 4, 0.260)
    else if (ec2InstanceType == "extra-large")
      new Ec2Instance(ec2InstanceType, 8, 0.520)
    else
      throw new IllegalArgumentException("invalid ec2InstanceType arguement: " + ec2InstanceType)
  }
}